import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class demo2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.nextLine().toUpperCase();
        String c = in.nextLine().toUpperCase();
        char[] c1 = c.toCharArray();
        String[] ss = s.split(" ");
        String temp = "";
        for (int i = 0; i < ss.length; i++) {
            temp += ss[i];
        }
        Map<Character, Integer> map = new HashMap<>();
        for (int i = 0; i < temp.length(); i++) {
            char ch = temp.charAt(i);
            if (!map.containsKey(ch)) {
                map.put(ch, 1);
            } else {
                int value = map.get(ch) + 1;
                map.put(ch, value);
            }
        }
        int count = 0;
        if (map.containsKey(c1[0])) {
            count = map.get(c1[0]);
        }
        System.out.println(count);
    }
}